package com.tengju.bff.interfaces.shared.servlet;

import org.apache.commons.lang3.StringUtils;

/**
 * 请求来源枚举
 * @author xiajichen
 */
public enum FromEnum {

    /**
     * 单创
     */
    DC("ABM", "DC"),
    /**
     * ABM
     */
    ABM("DT", "ABM"),
    /**
     * DATA_TREE
     */
    DT("tj", "tj"),
    ;

    private String key;
    private String value;

    FromEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据key取value
     *
     * @param key
     * @return
     */
    public static String getValueByKey(String key) {
        if (StringUtils.isBlank(key)) {
            return key;
        }
        for (FromEnum fromEnum : FromEnum.values()) {
            if (key.equals(fromEnum.getKey())) {
                return fromEnum.getValue();
            }
        }
        return key;
    }

}
